<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <title>天天生鲜-商品详情</title>
    <link rel="stylesheet" type="text/css" href="/static/css/reset.css">
    <link rel="stylesheet" type="text/css" href="/static/css/main.css">

</head>
<body>
{% include 'base.html' %}

<div class="search_bar clearfix">
    <a href="{% url 'user:index' %}" class="logo fl"><img src="/static/images/logo.png"></a>
    <div class="search_con fl">
        <input type="text" class="input_text fl" name="" placeholder="搜索商品">
        <input type="button" class="input_btn fr" name="" value="搜索">
    </div>
    <div class="guest_cart fr">
        <a href="{% url 'carts:cart' %}" class="cart_name fl">我的购物车</a>
        <div class="goods_count fl" id="show_count">1</div>
    </div>
</div>

<div class="navbar_con">
    <div class="navbar clearfix">
        <div class="subnav_con fl">
            <h1>全部商品分类</h1>
            <span></span>
            <ul class="subnav">
                <li><a href="#" class="fruit">新鲜水果</a></li>
                <li><a href="#" class="seafood">海鲜水产</a></li>
                <li><a href="#" class="meet">猪牛羊肉</a></li>
                <li><a href="#" class="egg">禽类蛋品</a></li>
                <li><a href="#" class="vegetables">新鲜蔬菜</a></li>
                <li><a href="#" class="ice">速冻食品</a></li>
            </ul>
        </div>
        <ul class="navlist fl">
            <li><a href="">首页</a></li>
            <li class="interval">|</li>
            <li><a href="">手机生鲜</a></li>
            <li class="interval">|</li>
            <li><a href="">抽奖</a></li>
        </ul>
    </div>
</div>

<div class="breadcrumb">
    <a href="#">全部分类</a>
    <span>></span>
    <a href="#">新鲜水果</a>
    <span>></span>
    <a href="#">商品详情</a>
</div>

<div class="goods_detail_con clearfix">
    <div class="goods_detail_pic fl"><img src="/static/images/{{ goods.photo }}"></div>

    <div class="goods_detail_list fr">
        <h3>{{ goods.name }}</h3>
        <p>{{ goods.intro }}</p>
        <div class="prize_bar">
            <span class="show_pirze">¥<em>{{ goods.price }}</em></span>
            <span class="show_unit">单  位：{{ goods.unit }}斤</span>
        </div>
        <div class="goods_num clearfix">
            <div class="num_name fl">数 量：</div>
            <div class="num_add fl">
                <input type="text" class="num_show fl" name="show_count" value="1">
                <a href="javascript:;" class="add fr">+</a>
                <a href="javascript:;" class="minus fr">-</a>
            </div>
        </div>
        <div class="total">总价：<em id="price">{{ goods.price }}</em></div>
        <div class="operate_btn">
            <a href="javascript:;" class="buy_btn">立即购买</a>
            <a href="javascript:;  " goods_id='{{ goods.id }}' class="add_cart" id="add_cart">加入购物车</a>
        </div>
    </div>
</div>

<div class="main_wrap clearfix">
    <div class="l_wrap fl clearfix">
        <div class="new_goods">
            <h3>新品推荐</h3>
            <ul>
                {% for new_good in new_goods %}
                    <li>
                        <a href="/goods/detail/{{ new_good.id }}" id="goods"><img
                                src="/static/images/{{ new_good.photo }}"></a>
                        <h4><a href="/goods/detail/{{ new_good.id }}" id="goods">{{ good.name }}</a></h4>
                        <div class="prize">{{ good.price }}</div>
                    </li>
                {% endfor %}

            </ul>
        </div>
    </div>

    <div class="r_wrap fr clearfix">
        <ul class="detail_tab clearfix">
            <li class="active">商品介绍</li>
            <li>评论</li>
        </ul>

        <div class="tab_content">
            <dl>
                <dt>商品详情：</dt>
                <dd>
                    {% for new_good in new_goods %}
                        <li>
                            {{ new_good.intro }}******{{ new_good.desc }}
                            <br>
                        </li>
                    {% endfor %}
                </dd>
            </dl>
        </div>

    </div>
</div>

<div class="footer">
    <div class="foot_link">
        <a href="#">关于我们</a>
        <span>|</span>
        <a href="#">联系我们</a>
        <span>|</span>
        <a href="#">招聘人才</a>
        <span>|</span>
        <a href="#">友情链接</a>
    </div>
    <p>CopyRight © 2016 北京天天生鲜信息技术有限公司 All Rights Reserved</p>
    <p>电话：010-****888 京ICP备*******8号</p>
</div>
<div class="add_jump"></div>

<script type="text/javascript" src="/static/js/jquery-1.12.4.min.js"></script>
<script type="text/javascript">
    var $add_x = $('#add_cart').offset().top;
    var $add_y = $('#add_cart').offset().left;

    var $to_x = $('#show_count').offset().top;
    var $to_y = $('#show_count').offset().left;


    $('#add_cart').click(function () {
        //获取商品数量和id
        g_id = $(this).attr('goods_id')
        count = $('.num_show').val()
        {#alert(g_id + ':' + count)#}
        //发送ajax请求
        params = {'goods_id': g_id, 'count': count}
        $.post('/carts/add/', params, function (data) {
                if (data.res == 1) {
                    alert('添加成功')
                    $(".add_jump").css({'left': $add_y + 80, 'top': $add_x + 10, 'display': 'block'})
                    $(".add_jump").stop().animate({
                            'left': $to_y + 7,
                            'top': $to_x + 7
                        },
                        "fast", function () {
                            $(".add_jump").fadeOut('fast', function () {
                                $('#show_count').html(2);
                            });

                        });
                } else {
                    alert("添加失败")
                }
            }
        )


    })

    /**价格**/
    $(function () {
        var goods_nums = $(".num_show");
        var goods_price = $("#price");
        price = Number(goods_price.text())
        $(".add").on("click", function () {
            goods_nums.val(parseFloat(goods_nums.val()) + 1);
            goods_price.text((Number(goods_price.text()) + price).toFixed(2))
        })


        $(".minus").on("click", function () {
            if (parseFloat(goods_nums.val()) > 1) {
                goods_nums.val(parseFloat(goods_nums.val()) - 1);
                goods_price.text((Number(goods_price.text()) - price).toFixed(2))
            }

        })
    })

</script>

</body>
</html>